<?php

namespace app\api\model;

class MessageRead extends \app\common\model\MessageRead
{
    /**
     * 获取个人已读列表
     * @param $oauthId
     * @return array
     */
    public static function getList($oauthId)
    {
        return static::where(['oauth_id' => $oauthId])
            ->column('id', 'message_id');
    }

    /**
     * 查看信息是否已读
     * @param $oauthId
     * @param $messageId
     * @return array|\PDOStatement|string|\think\Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public static function getOne($oauthId, $messageId)
    {
        return static::where([
            'oauth_id' => $oauthId,
            'message_id' => $messageId
        ])->find();
    }

    /**
     * 添加一条记录
     * @param $oauthId
     * @param $messageId
     * @return mixed
     */
    public static function addOne($oauthId, $messageId)
    {
        $model = static::create([
            'oauth_id' => $oauthId,
            'message_id' => $messageId
        ]);
        return isset($model->id) ? true : false;
    }
}